/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import AdminOperations.AdminManageModerator;
import beans.ForModOperations;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import xmlMapping.Moderatorpermessions;

/**
 *
 * @author root
 */
public class AdminModeratorOperations extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String success = "success";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override       
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward=null;
        int modId=((ForModOperations)form).getModId();
        String userName =((ForModOperations)form).getUserName();
        AdminManageModerator aMM=new AdminManageModerator();
        String type=((ForModOperations)form).getType();
        if(type.equals("demot")){
            aMM.demoteModerator(modId);
            forward=mapping.findForward("success");
        }
        else if(type.equals("getperm")){
            Moderatorpermessions modperm=aMM.getModeratorpermessions(modId);
            ForModOperations fMO=new ForModOperations();
            
            System.out.println(String.valueOf(modperm.isBanuser()));
            fMO.setBanuser(String.valueOf(modperm.isBanuser()));
            fMO.setDeletepost(String.valueOf(modperm.isDeletepost()));
            fMO.setDeletethread(String.valueOf(modperm.isDeletethread()));
            fMO.setEditpost(String.valueOf(modperm.isEditpost()));
            fMO.setEditthread(String.valueOf(modperm.isEditthread()));
            fMO.setEdituser(String.valueOf(modperm.isEdituser()));
            fMO.setSupper(String.valueOf(modperm.isSupper()));
            fMO.setSuspenduser(String.valueOf(modperm.isSuspenduser()));
            fMO.setModId(modId);
            fMO.setUserName(userName);
            
            
            
            request.setAttribute("fMO", fMO);
         
            forward=mapping.findForward("getperm");
        }
        
        return forward;
    }
}
